package ta.server;

import gwt.trading.client.StockQuote;

import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import ta.client.TradingService;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * @author Iulian Costan (iulian.costan@gmail.com)
 *
 */
public class TradingServiceImpl extends RemoteServiceServlet implements TradingService {
	private static final long serialVersionUID = 1L;

	private static final Log log = LogFactory.getLog(TradingServiceImpl.class);
	
	private static List<StockQuote> quotes = new ArrayList<StockQuote>();

	static {
		quotes.add(new StockQuote(0, new GregorianCalendar(2006, 11, 10).getTime(), 3.18f, 3.23f, 3.17f, 3.18f, 2930430));
		quotes.add(new StockQuote(1, new GregorianCalendar(2006, 11, 9).getTime(), 3f, 3.19f, 2.93f, 3.16f, 10117784));
		quotes.add(new StockQuote(2, new GregorianCalendar(2006, 11, 8).getTime(), 3.26f, 3.28f, 3.02f, 3.02f, 9044662));
		quotes.add(new StockQuote(3, new GregorianCalendar(2006, 11, 7).getTime(), 3.41f, 3.42f, 3.27f, 3.29f, 8144620l));
		quotes.add(new StockQuote(4, new GregorianCalendar(2006, 11, 6).getTime(), 3.30f, 3.42f, 3.30f, 3.40f, 3295144l));
		quotes.add(new StockQuote(5, new GregorianCalendar(2006, 11, 3).getTime(), 3.29f, 3.34f, 3.22f, 3.30f, 2772201l));
		quotes.add(new StockQuote(6, new GregorianCalendar(2006, 11, 2).getTime(), 3.25f, 3.33f, 3.24f, 3.28f, 5407025l));
		quotes.add(new StockQuote(7, new GregorianCalendar(2006, 11, 1).getTime(), 3.11f, 3.23f, 3.06f, 3.2f, 5448892l));
	}

	public StockQuote[] getQuotes(String symbol) {
		log.debug("Serving quotes ... size=" + quotes.size());
		return quotes.toArray(new StockQuote[0]);
	}

}
